import cyptjs from 'crypto-js'

/** AES加密 */
const key = 'bGvnMc62sh5RV6zP'
const iv = '1eZ43DLcYtV2xb3Y'

export const encrypt = (word: string) => {
  const srcs = cyptjs.enc.Utf8.parse(word)
  const encrypted = cyptjs.AES.encrypt(srcs, cyptjs.enc.Utf8.parse(key), {
    iv: cyptjs.enc.Utf8.parse(iv),
    mode: cyptjs.mode.CBC,
    padding: cyptjs.pad.Pkcs7
  })
  return encrypted.toString()
}

/** AES解密 */
export const decrypt = (word: string) => {
  const decrypt = cyptjs.AES.decrypt(word, cyptjs.enc.Utf8.parse(key), {
    iv: cyptjs.enc.Utf8.parse(iv),
    mode: cyptjs.mode.CBC,
    padding: cyptjs.pad.Pkcs7
  })
  return cyptjs.enc.Utf8.stringify(decrypt).toString()
}
